<template>
<div :class="['nav-bar',icon?'':'no-right']">
  <van-icon class="left" name="arrow-left" :size="28" @click="$router.go(-1)" />
  <div class="title">{{title}}</div>
  <van-icon v-if="icon" :name="icon" :size="28" />
  <slot name="right" />
</div>
</template>
<script>
export default {
  name: 'NavBar',
  props:{
    title: {
      type: String,
      default: ''
    },
    icon: {
      type: String,
      default: ''
    }
  }
};
</script>
<style scoped lang="scss">
.nav-bar{
  margin-top: 20px;
  width: 100%;
  padding: 0 3%;
  box-sizing: border-box;
  height: 45px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #ffffff;
  position: relative;
  .title{
    width: calc(100% - 46px - 28px);
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-align: center;
    text-overflow: ellipsis;
  }
  &.no-right{
    .title {
      width: calc(100% - 46px);
      padding-right: 28px;
    }
  }
}
</style>
